$(document).ready(function () {
    $('#grid').on('click', 'div.certification i.fa-times', function () {
        appBosch.refreshDashboard = false;
        appBosch.certificationDestroyId = $(this).data('id');
        var window = $("#wndDestroyCertification");
        window.removeClass('hidden');
        if (!window.data("kendoWindow")) {
            window.kendoWindow({
                title: 'Eliminar certificación',
                actions: [
                    "Close"
                ],
                width: 500,
                close: function () {
                    if (appBosch.refreshDashboard === true) {
                        $('#grid').data('kendoGrid').dataSource.read();
                    }
                },
                open: function () {
                    $("#wndDestroyCertification textarea").val('');
                    $('#motivoEliminacion').focus();
                    this.center();
                }
            }).data("kendoWindow").center();
            $('#motivoEliminacion').focus();
        }
        else {
            window.data("kendoWindow").open();
        }
    });

    $('#wndDestroyCertification button').click(function () {
        var com = $('#wndDestroyCertification textarea').val().trim();
        if (com === '') {
            alert('El motivo de la eliminación es obligatorio');
        }
        else {
            appBosch.refreshDashboard = true;
            $('#wndDestroyCertification i.fa-refresh').removeClass('hidden');
            $('#wndDestroyCertification button').addClass('hidden');
            $.get(appBosch.urlDestroyCertification, {cId: appBosch.certificationDestroyId, c: com}, function () {
                $("#wndDestroyCertification").data('kendoWindow').close();
                $('#wndDestroyCertification i.fa-refresh').addClass('hidden');
                $('#wndDestroyCertification button').removeClass('hidden');
            });
        }
    });
});